package cn.virens.library.http.callback;

import android.content.Context;

import org.xutils.common.Callback;

import cn.virens.library.http.response.ServerResponse;

/**
 * 缓存网络响应类
 * Created by virens on 2017/2/19.
 */
public abstract class HttpCacheCallback<T> extends HttpCallback<T> implements Callback.CacheCallback<T> {
    public HttpCacheCallback(Context context) {
        super(context);
    }

    @Override
    public void onSuccess(T result) {
        if (result != null) super.onSuccess(result);
    }

    @Override
    public boolean onCache(T result) {
        if (result == null) {
            return false;
        } else if (result instanceof ServerResponse && !((ServerResponse) result).success()) {
            return false;
        } else {
            return onResult(result);
        }
    }
}
